package com.egghiro.j2se.game.sace.device.factory.bulletfactory;

import com.egghiro.framework.j2se.game.core.model.actor.IActor2D;
import com.egghiro.j2se.game.sace.model.actor.BulletCluster;
import com.egghiro.j2se.game.sace.model.actor.FlyerComponent;

public abstract class BulletFactory extends FlyerFactory {
    private static final long DEFAULT_LIFE = 2000;

    @Override
    public FlyerComponent createFlyer(int x, int y, double angle, IActor2D target) {
        return createFlyer(x, y, angle, target, DEFAULT_LIFE);
    }

    public abstract FlyerComponent createFlyer(int x, int y, double speed, double angle, IActor2D target, long life);

    @Override
    public FlyerComponent createFlyer(int x, int y, double startAngle, double arcAngle, double angleStep, IActor2D target) {
        return createFlyer(x, y, startAngle, arcAngle, angleStep, target, DEFAULT_LIFE);
    }

    @Override
    public FlyerComponent createFlyer(int x, int y, double startAngle, double arcAngle, double angleStep,
            IActor2D target, long life) {
        BulletCluster list = new BulletCluster();
        if (angleStep < 5) { // 最小角度。另外，arcAngle为0的时候，这可以保证不会死循环
            angleStep = 5;
        }
        for (double angle = 0; angle <= arcAngle; angle += angleStep) { // TODO 此逻辑的话角度会有重复。
            list.add(createFlyer(x, y, startAngle + angle, target, life));
        }
        return list;
    }

    public FlyerComponent createFlyer(int x, int y, double speed, double startAngle, double arcAngle, double angleStep,
            IActor2D target) {
        return createFlyer(x, y, speed, startAngle, arcAngle, angleStep, target, DEFAULT_LIFE);
    }

    public FlyerComponent createFlyer(int x, int y, double speed, double startAngle, double arcAngle, double angleStep,
            IActor2D target, long life) {
        BulletCluster list = new BulletCluster();
        if (angleStep < 5) {// 最小角度。另外，arcAngle为0的时候，这可以保证不会死循环
            angleStep = 5;
        }
        for (double angle = 0; angle <= arcAngle; angle += angleStep) {// TODO 此逻辑的话角度会有重复。
            list.add(createFlyer(x, y, speed, startAngle + angle, target, life));
        }
        return list;
    }
}
